home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / Asm / Demos / Stars8.s < prev    next >
Encoding:
Text File  |  1997-12-16  |  7.7 KB  |  320 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      3D StarField 8
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;Same as the first starfield demo but runs in 8 colours.  Default is 500
  7. ;stars which runs fine on my A1200+Fast - but try 5000 stars or more for a
  8. ;real visual experience :-)
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "dpkernel/dpkernel.i"
  12.  
  13. NSTARS    =    700    ;Number of stars
  14.  
  15. XSPEED    =    -4
  16. YSPEED    =    6
  17. ZSPEED    =    2
  18.  
  19. SCR_HEIGHT =    256
  20. SCR_WIDTH  =    320
  21.  
  22.     SECTION    "Demo",CODE
  23.  
  24. ;==========================================================================;
  25. ;                             INITIALISE DEMO
  26. ;==========================================================================;
  27.  
  28.     STARTDPK
  29.  
  30. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  31.     move.l    DPKBase(pc),a6
  32.     lea    ScreenTags(pc),a0
  33.     sub.l    a1,a1
  34.     CALL    Init
  35.     tst.l    d0
  36.     beq.s    .Exit
  37.  
  38.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  39.     CALL    Get
  40.     move.l    d0,JoyData
  41.     beq.s    .Exit
  42.     move.l    d0,a0    ;Initialise the joydata structure.
  43.     sub.l    a1,a1
  44.     CALL    Init
  45.     tst.l    d0
  46.     beq.s    .Exit
  47.  
  48.     move.l    Screen(pc),a0
  49.     CALL    Display
  50.  
  51.     bsr.s    Main
  52.  
  53. .Exit    move.l    DPKBase(pc),a6
  54.     move.l    JoyData(pc),a0
  55.     CALL    Free
  56.     move.l    Screen(pc),a0
  57.     CALL    Free
  58.     MOVEM.L    (SP)+,A0-A6/D1-D7
  59.     moveq    #ERR_OK,d0
  60.     rts
  61.  
  62. ;==========================================================================;
  63. ;
  64. ;==========================================================================;
  65.  
  66.     ;Randomize star coordinates
  67.  
  68. Main:    lea    StarCoords,a0    ;a0 = Ptr to star co-ordinates.
  69.     move.w    #NSTARS-1,d7
  70.     move.l    DPKBase(pc),a6
  71. .loop1    move.w    #8192,d1
  72.     CALL    SlowRandom
  73.     move.w    d0,(a0)+
  74.     CALL    SlowRandom
  75.     move.w    d0,(a0)+
  76.     CALL    SlowRandom
  77.     move.w    d0,(a0)+
  78.     dbra    d7,.loop1
  79.  
  80.     ;Construct perspective table
  81.  
  82.     lea    PersTable,a0    ;a0 = ptr to perspective table.
  83.     moveq    #0,d1    ;d1 = Starting at 0.
  84. .loop2    move.l    #$95FFFF,d2    ;d2 = $95FFFF
  85.     move.l    d1,d3    ;d3 = d1
  86.     add.w    #300,d3    ;d3 = ++300
  87.     divu    d3,d2    ;d2 = ($95ffff)/d3
  88.     move.w    d2,(a0)+    ;a0 = d2+
  89.     addq.w    #1,d1    ;d1 = ++1
  90.     cmp.w    #8192,d1    ;d1 = Equal to 8192?
  91.     bne.s    .loop2
  92.  
  93.     ;Construct plot tables for fast drawing.
  94.  
  95.     lea    PlotXTable,a0    ;a0 = X table - byte positions.
  96.     lea    PlotBTable,a1    ;a1 = Bit table (X related).
  97.     lea    PlotYTable,a2    ;a2 = Y table - line position.
  98.     moveq    #0,d0    ;d0 = 00
  99. .loop3    move.w    d0,d1    ;d1 = d0
  100.     lsr.w    #3,d1    ;d1 = (d0)<<3
  101.     move.w    d1,(a0)+    ;a0 = d1+
  102.  
  103.     move.w    d0,d1    ;d1 = d0
  104.     eor.w    #$FFFF,d1    ;d1 = (d0) eor $ffff
  105.     and.w    #%00000111,d1    ;d1 = &%00000111
  106.     move.w    d1,(a1)+    ;a1 = BitSet++
  107.  
  108.     cmp.w    #SCR_HEIGHT,d0    ;Write out the Y values for the
  109.     bge.s    .plot2    ;table.
  110.     move.w    d0,d1    ;d1 = Line Number.
  111.     mulu    #120,d1    ;d1 = (LineNumber)*80
  112.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  113.  
  114. .plot2    addq.w    #1,d0
  115.     cmp.w    #SCR_WIDTH,d0
  116.     bne.s    .loop3
  117.  
  118. ;==========================================================================;
  119. ;                                MAIN LOOP
  120. ;==========================================================================;
  121.  
  122. MainLoop:
  123.     move.l    SCRBase(pc),a6
  124.     CALL    scrWaitAVBL
  125.  
  126.     move.l    Screen(pc),a0
  127.     CALL    scrSwapBuffers
  128.  
  129. ;==========================================================================;
  130. ;                             STAR ANIMATION
  131. ;==========================================================================;
  132.  
  133.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  134.     add.w    #XSPEED,d0    ;d0 = (StarXPos)+XSPEED
  135.     add.w    #YSPEED,d1    ;d1 = (StarYPos)+YSPEED
  136.     add.w    #ZSPEED,d2    ;d2 = (StarZPos)+ZSPEED
  137.     and.w    #%0000011111111111,d0
  138.     and.w    #%0000011111111111,d1
  139.     and.w    #%0000011111111111,d2
  140.     movem.w    d0/d1/d2,StarXPos
  141.  
  142.     lea    Sinus(pc),a0    ;a0 = Sinus table.
  143.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  144.     add.w    (a0,d0.w),d3
  145.     add.w    (a0,d1.w),d4
  146.     add.w    (a0,d2.w),d5
  147.     movem.w    d3/d4/d5,StarXAdd
  148.  
  149. ;===========================================================================;
  150. ;                              SCREEN CLEAR
  151. ;===========================================================================;
  152. ;Let the blitter clear our 3rd screen while the CPU draws the stars.
  153.  
  154.     move.l    BLTBase(pc),a6
  155.     move.l    Screen(pc),a1    ;a1 = GameScreen
  156.     move.l    GS_Bitmap(a1),a0    ;a0 = Bitmap
  157.     move.l    GS_MemPtr3(a1),BMP_Data(a0)
  158.     CALL    bltClearBitmap
  159.  
  160. ;==========================================================================;
  161. ;                               DRAW STARS
  162. ;==========================================================================;
  163.  
  164.     lea    StarCoords,a0    ;Draw starfield
  165.     lea    PersTable,a1    ;a1 = Perspective table.
  166.     lea    PlotXTable,a2    ;a2 = X table.
  167.     lea    PlotBTable,a3    ;a3 = Bit table.
  168.     lea    PlotYTable,a4    ;a4 = Y table.
  169.  
  170.     move.l    Screen(pc),a6
  171.     move.l    GS_MemPtr2(a6),a6
  172.  
  173.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  174.     add.w    #4096,d3    ;d3 = ++4096
  175.     add.w    #4096,d4    ;d4 = ++4096
  176.  
  177.     move.w    #NSTARS-1,d7
  178.  
  179. .draw    movem.w    (a0)+,d0/d1/d2    ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  180.     add.w    d3,d0    ;Increase XPos.
  181.     and.w    #8191,d0    ;d0 = And'd
  182.     sub.w    #4096,d0    ;d0 = --4096
  183.  
  184.     add.w    d4,d1    ;Y-movement
  185.     and.w    #8191,d1    ;d1 = And'd
  186.     sub.w    #4096,d1    ;d1 = --4096
  187.  
  188.     add.w    d5,d2    ;Z-movement
  189.     and.w    #8191,d2
  190.     add.w    d2,d2    ;d2 = *2 [word]
  191.     move.w    (a1,d2.w),d6    ;d6 = Read from Perspective table.
  192.  
  193.     muls    d6,d0    ;X-projection
  194.     swap    d0
  195.     add.w    #176,d0
  196.  
  197.     cmp.w    #SCR_WIDTH-1,d0
  198.     bhi    .nodraw
  199.     muls    d6,d1    ;Y-projection
  200.     swap    d1
  201.     add.w    #136,d1
  202.     cmp.w    #SCR_HEIGHT-1,d1
  203.     bhi    .nodraw
  204.  
  205.     add.w    d0,d0    ;d0 = *2 [word]
  206.     add.w    d1,d1    ;d1 = *2 [word]
  207.     move.w    (a4,d1.w),d6    ;d6 = Plot Y.
  208.     add.w    (a2,d0.w),d6    ;d6 = ++PlotX.
  209.     move.w    (a3,d0.w),d0    ;d0 = BitValue.
  210.  
  211. .draw1    cmp.w    #4000,d2    ;Now draw the star according to
  212.     bgt.s    .draw2    ;its position in the Z axis.
  213.     bset    d0,(a6,d6.w)
  214.     dbra    d7,.draw
  215.     bra.s    .done
  216.  
  217. .draw2    cmp.w    #6000,d2
  218.     bgt.s    .draw3
  219.     bset    d0,40(a6,d6.w)
  220.     dbra    d7,.draw
  221.     bra.s    .done
  222.  
  223. .draw3    cmp.w    #8000,d2
  224.     bgt.s    .draw4
  225.     bset    d0,(a6,d6.w)
  226.     bset    d0,40(a6,d6.w)
  227.     dbra    d7,.draw
  228.     bra.s    .done
  229.  
  230. .draw4    cmp.w    #10000,d2
  231.     bgt.s    .draw5
  232.     bset    d0,80(a6,d6.w)
  233.     dbra    d7,.draw
  234.     bra.s    .done
  235.  
  236. .draw5    cmp.w    #12000,d2
  237.     bgt.s    .draw6
  238.     bset    d0,(a6,d6.w)
  239.     bset    d0,80(a6,d6.w)
  240.     dbra    d7,.draw
  241.     bra.s    .done
  242.  
  243. .draw6    cmp.w    #14000,d2
  244.     bgt.s    .draw7
  245.     bset    d0,40(a6,d6.w)
  246.     bset    d0,80(a6,d6.w)
  247.     dbra    d7,.draw
  248.     bra.s    .done
  249.  
  250. .draw7    bset    d0,(a6,d6.w)
  251.     bset    d0,40(a6,d6.w)
  252.     bset    d0,80(a6,d6.w)
  253. .nodraw    dbra    d7,.draw
  254.  
  255. .done    move.l    DPKBase(pc),a6
  256.     move.l    JoyData(pc),a0
  257.     CALL    Query
  258.     move.l    JoyData(pc),a0
  259.     move.l    JD_Buttons(a0),d0
  260.     sub.l    a1,a1
  261.     moveq    #$00,d1
  262.     btst    #JB_LMB,d0
  263.     beq    MainLoop
  264.     rts
  265.  
  266. ;===========================================================================;
  267. ;                                  DATA
  268. ;===========================================================================;
  269.  
  270. JoyData:    dc.l  0
  271.  
  272. ScreenTags:    dc.l  TAGS_SCREEN
  273. Screen:        dc.l  0
  274.         dc.l  GSA_Palette,.palette
  275.         dc.l  GSA_Width,320
  276.         dc.l  GSA_Height,256
  277.         dc.l  GSA_Attrib,TPLBUFFER
  278.         dc.l  GSA_ScrMode,LORES
  279.         dc.l    GSA_BitmapTags,0
  280.         dc.l    BMA_Type,ILBM
  281.         dc.l    BMA_AmtColours,8
  282.         dc.l    TAGEND,0
  283.         dc.l  TAGEND
  284.  
  285. .palette    dc.l  PALETTE,8
  286.         dc.l  $000000,$f0f0f0,$c0c0c0,$909090 ;%000, %100, %010, %110
  287.         dc.l  $707070,$505050,$303030,$101010 ;%001, %101, %011, %111
  288.  
  289. ;===========================================================================;
  290. ;                                STAR DATA
  291. ;===========================================================================;
  292.  
  293. StarXAdd:    dc.w  33    ;Star stuff
  294. StarYAdd:    dc.w  12
  295. StarZAdd:    dc.w  -114
  296.  
  297. StarXPos:    dc.w  0    ;Sinus positions
  298. StarYPos:    dc.w  310
  299. StarZPos:    dc.w  1280
  300.  
  301.     INCLUDE    "GMSDev:source/asm/demos/StarSinus.i"
  302.  
  303.     SECTION    Storage,BSS
  304.  
  305. StarCoords:    ds.w  NSTARS*3    ;Star coordinates
  306. PersTable:    ds.w  8192    ;Perspective table
  307. PlotXTable:    ds.w  SCR_WIDTH    ;Plot tables
  308. PlotBTable:    ds.w  SCR_WIDTH
  309. PlotYTable:    ds.w  SCR_HEIGHT
  310.  
  311. ;===========================================================================;
  312.  
  313. ProgName:    dc.b  "Stars 8",0
  314. ProgAuthor:    dc.b  "Paul Manias",0
  315. ProgDate:    dc.b  "18 November 1997",0
  316. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1997.  Freely distributable.",0
  317. ProgShort:    dc.b  "8 colour star field demonstration.",0
  318.         even
  319.  
  320.